package com.avic.rong.shoppingCar.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.avic.rong.MainActivity;
import com.avic.rong.R;
import com.avic.rong.activity.login.LoginActivity;

/**
 * Created by Chenjiaxin on 2019/7/19 08:44
 * E-Mail Address：16601203965@163.com
 */
public class ShoppingCarWeiDLRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private LayoutInflater inflater;
    private static final int TopView = 0;
    private static final int BottomRv = 1;
    private int currentType = 0;

    public ShoppingCarWeiDLRvAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getItemViewType(int position) {
        switch (position){
            case TopView:
                currentType = TopView;
                break;
            case BottomRv:
                currentType = BottomRv;
                break;
        }
        return currentType;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        if (i == TopView) {
            View view = inflater.inflate(R.layout.view_shoppingcar_weidl, viewGroup, false);
            return new TopViewViewHolder(view);
        } else {
            View view = inflater.inflate(R.layout.view_shoppingcar_cailove, viewGroup, false);
            return new BottomRvViewHolder(view);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        if (getItemViewType(i) == TopView) {
            TopViewViewHolder holder = (TopViewViewHolder) viewHolder;
            holder.denglu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, LoginActivity.class);
                    context.startActivity(intent);
                }
            });
            holder.gouwu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, MainActivity.class);
                    context.startActivity(intent);
                }
            });
        } else {
            BottomRvViewHolder holder = (BottomRvViewHolder) viewHolder;
            GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2);
            holder.rv.setLayoutManager(gridLayoutManager);
//            MineLikeAdapter mineLikeAdapter = new MineLikeAdapter(context);
//            holder.rv.setAdapter(mineLikeAdapter);
        }
    }

    @Override
    public int getItemCount() {
        return 2;
    }

    class TopViewViewHolder extends RecyclerView.ViewHolder {
        TextView denglu, gouwu;
        public TopViewViewHolder(@NonNull View itemView) {
            super(itemView);
            denglu = itemView.findViewById(R.id.shoppingCar_WeiDL_DengLu);
            gouwu = itemView.findViewById(R.id.shoppingCar_WeiDL_QuGouWu);
        }
    }

    class BottomRvViewHolder extends RecyclerView.ViewHolder {
        RecyclerView rv;
        public BottomRvViewHolder(@NonNull View itemView) {
            super(itemView);
            rv = itemView.findViewById(R.id.shoppingCar_WeiDL_Rv);
        }
    }
}
